package middleware.p2p.global.monitor;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.jws.WebService;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import middleware.p2p.log.MiddlewareMonitorEvent;
import middleware.p2p.log.QueueType;

/**
 * Session Bean implementation class GlobalMonitor
 */
@Stateless
@WebService(name="GlobalMonitor", serviceName="GlobalMonitorService")
public class GlobalMonitor implements GlobalMonitorRemote {
	@EJB(name="ejb/MonitorQueue",beanInterface=middleware.p2p.global.monitor.MonitorQueueManagerLocal.class)
	private MonitorQueueManagerLocal queue;
    /**
     * Default constructor. 
     */
    public GlobalMonitor() {
    	super();        
    	try {
	        Context ctx = new InitialContext();
			this.queue = (MonitorQueueManagerLocal)ctx.lookup("java:comp/env/ejb/MonitorQueue");
		} catch (NamingException e) {
			e.printStackTrace();
		}        
    }

	@Override
	public boolean push(QueueType queueType,MiddlewareMonitorEvent event) {				
		//System.out.println("&&&"+queueType+"\n"+event.toXmlString());
		return this.queue.enqueue(queueType, event);
	}

	@Override
	public boolean resetClock(String componentId) {
		return this.queue.resetClock(componentId);
	}
}
